<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>回调函数</title>
</head>

<body>
    <div></div>
</body>
<script>
    function f1(fn) {
        fn()
    }

    function f2() {
        console.log('f2被调用了')
    }
    //函数作为参数
    f1(f2)
    //函数作为参数--回调函数
    document.addEventListener("click", f2, false)


    //函数返回对象
    function f3() {
        let name = 'tom'
        let age = 20
        return {
            name,
            age
        }
    }
    console.log(f3())



    //闭包： 一个函数A返回的值B是函数，B成为A的闭包
    function f4() {
        let a = 20
        let b = 10
        let fn = function () {
            return a + b
        }
        return fn
    }

    let f = f4()
    let res = f()
    console.log(f)
    console.log(res)
</script>

</html>